package liuds.music.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.List;

import liuds.music.R;
import liuds.music.model.Music;

/**
 * Created by Administrator on 2018/5/4.
 */

public class SearchAdapter extends BaseAdapter {
    private Context context;
    private List<Music> music;

    public SearchAdapter(Context context, List<Music> music){
        this.context = context;
        this.music = music;
    }

    @Override
    public int getCount() {
        return music.size();
    }

    @Override
    public Music getItem(int position) {
        return music.get(position);
    }

    @Override
    public long getItemId(int position) {
        return music.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.search_item,null);
        }
        TextView title = convertView.findViewById(R.id.title);
        title.setText(music.get(position).getTitle());

        if(position==music.size()){
            View line = convertView.findViewById(R.id.line);
            line.setVisibility(View.GONE);
        }

        return convertView;
    }

}
